Ext.define('FM.controller.form.user.AddUserFormController', {
	extend : 'FM.controller.form.FormController',
	views : ['form.user.AddUserForm'],
	refs : [ {
		ref : 'sel_addUserForm',
		selector : 'AddUserForm'
	} ],
	init : function() {
		console.log('The form buttons was rendered');
		appTab(Ext.getCmp('Center'), 'addUserForm', '', '添加用户', 'AddUserForm');
		this.control({
			'button[action=save]' : {
				click : this.save
			},
			'button[action=reset]' : {
				click : this.reset
			},
		});
	},
	save : function(button, e){
		if (this.getSel_addUserForm().isValid()) {
			this.getSel_addUserForm().submit({
				url : 'user/save.html',
				method : 'post',
				waitTitle : '请稍候',
				waitMsg : '数据正在提交…………',
				success : function(form, action) {
					if(action.result.msg = 'success'){
						form.reset();
						Ext.Msg.alert('成功：', '添加用户成功！');
					} else {
						Ext.Msg.alert('失败：', action.result.msg);
					}
				},
				failure : function(form, action) {
					if (action.failureType === Ext.form.action.Action.CONNECT_FAILURE) {
                        Ext.Msg.alert('错误：',
                            'Status:'+action.response.status+': '+
                            action.response.statusText);
                    }
                    if (action.failureType === Ext.form.action.Action.SERVER_INVALID){
                        // server responded with success = false
                        Ext.Msg.alert('错误：', action.result.msg);
                    }
				}
			});
		}
	},
	reset: function(button, e){
		this.getSel_addUserForm().getForm().reset();
	}
});
